﻿
using Light.Framework.Component;
using Light.Coin.Model;
using Light.Coin.Contract;
using Light.Framework.Model;
using Light.Framework.Castle;
using Light.Utility;

namespace Light.Coin.Component
{
    public class CoinLogComponent : BaseComponent<CoinLog>, ICoinLogComponent
    {
        public override Light.Utility.OperateResult Create(CoinLog obj)
        {
            OperateResult result = new OperateResult();

            if (obj.User == null)
            {
                result.IsSucced = false;
                result.Message = "用户不能为空";
                return result;
            }

            /*
             * 计算当前用户积分余额 
             */
            if (obj.User == null)
                obj.User = (User)ServerApplication.User;
            if (obj.Organization == null)
                obj.Organization = obj.User.Organization;
            obj.User.Coins += obj.Coins;
            obj.Balance = obj.User.Coins;
            return base.Create(obj);
        }
    }
}
